<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>off</title>
</head>

<body>
    <div id="content"></div>
    <button class="ew-btn" type="button" id="addEventBtn">点击我添加事件</button>
    <button class="ew-btn" type="button" id="removeEventBtn">点击我移除事件</button>
    <script type="text/javascript">
        const off = (el, type, callback, useCapture = false) => {
            if (el && typeof type === 'string' && typeof callback === 'function') {
                el.removeEventListener(type, callback, useCapture);
            }
        }
        const on = (el, type, callback, useCapture = false) => {
            if (el && typeof type === 'string' && typeof callback === 'function') {
                el.addEventListener(type, callback, useCapture);
            }
        }
        const callback = () => {
            document.getElementById('content').textContent = '你看这不就是惊喜吗?打开浏览器控制台会有更多惊喜哦!';
            console.log("%c ", "padding:50px;border-radius:5px;background: url('https://img1.baidu.com/it/u=2051155272,478750855&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500')no-repeat center/cover;");
        };
        on(document.getElementById('addEventBtn'),'click',callback);
        const offCallback = () => {
            off(document.getElementById('addEventBtn'), 'click', callback);
        }
        // 添加事件
        on(document.getElementById('removeEventBtn'),'click',offCallback);
    </script>
</body>

</html>